home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / tm / tm-file.el.z / tm-file.el
Encoding:
Text File  |  1998-05-21  |  2.6 KB  |  94 lines

  1. ;;; tm-file.el --- tm-view internal method for file extraction
  2.  
  3. ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
  4.  
  5. ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
  6. ;; modified by Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
  7. ;; Version: $Id: tm-file.el,v 7.10 1997/03/12 14:21:10 morioka Exp $
  8. ;; Keywords: mail, news, MIME, multimedia, file, extract
  9.  
  10. ;; This file is part of tm (Tools for MIME).
  11.  
  12. ;; This program is free software; you can redistribute it and/or
  13. ;; modify it under the terms of the GNU General Public License as
  14. ;; published by the Free Software Foundation; either version 2, or (at
  15. ;; your option) any later version.
  16.  
  17. ;; This program is distributed in the hope that it will be useful, but
  18. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20. ;; General Public License for more details.
  21.  
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  24. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25. ;; Boston, MA 02111-1307, USA.
  26.  
  27. ;;; Code:
  28.  
  29. (require 'tm-view)
  30.  
  31. (defun mime-article/extract-file (beg end cal)
  32.   (goto-char beg)
  33.   (let* ((name
  34.       (save-restriction
  35.         (narrow-to-region beg end)
  36.         (mime-article/get-filename cal)
  37.         ))
  38.      (encoding (cdr (assq 'encoding cal)))
  39.      (filename
  40.           (if (and name (not (string-equal name "")))
  41.           (expand-file-name name
  42.                 (call-interactively
  43.                  (function
  44.                   (lambda (dir)
  45.                     (interactive "DDirectory: ")
  46.                     dir))))
  47.         (call-interactively
  48.          (function
  49.           (lambda (file)
  50.         (interactive "FFilename: ")
  51.         (expand-file-name file))))))
  52.      (the-buf (current-buffer))
  53.      (tmp-buf (generate-new-buffer (file-name-nondirectory filename)))
  54.      )
  55.     (if (file-exists-p filename)
  56.         (or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
  57.             (error "")))
  58.     (re-search-forward "\n\n")
  59.     (append-to-buffer tmp-buf (match-end 0) end)
  60.     (save-excursion
  61.       (set-buffer tmp-buf)
  62.       (mime-decode-region (point-min)(point-max) encoding)
  63.       (as-binary-output-file (write-file filename))
  64.       (kill-buffer tmp-buf)
  65.       )))
  66.  
  67.  
  68. ;;; @ setup
  69. ;;;
  70.  
  71. (set-atype 'mime/content-decoding-condition
  72.        '((type . "application/octet-stream")
  73.          (method . mime-article/extract-file)
  74.          )
  75.        'ignore '(method)
  76.        'replacement)
  77.  
  78. (set-atype 'mime/content-decoding-condition
  79.        '((mode . "extract")
  80.          (method . mime-article/extract-file)
  81.          )
  82.        'remove
  83.        '((method "tm-file"  nil 'file 'type 'encoding 'mode 'name)
  84.          (mode . "extract"))
  85.        'replacement)
  86.  
  87.  
  88. ;;; @ end
  89. ;;;
  90.  
  91. (provide 'tm-file)
  92.  
  93. ;;; end of tm-file.el
  94.